import { request } from "../../utils/request";
import { ElMessage } from "element-plus";
import useUserStore from "../../store/user";
import useOperationStore from '../../store/operation'
// 获取业务数据（管理用）
export function reqOperationData(){
  return request(
    {
      url:'api/lab/admin/v1/operation/query',
      method:'get'
    }
  )
}
// 新增业务
export const addOperation = async (data) => {
  return request({
    url: 'api/lab/admin/v1/operation/save',
    method: 'post',
    data
  })
}

// 修改业务
export const modifyOperation = async (data) => {
  return request({
    url: 'api/lab/admin/v1/operation/update',
    method: 'put',
    data
  })
}

// 获取业务数据(业务页用)
export const reqOperations = async (companyId) => {
  return request({
    url: 'api/lab/admin/v1/operation/entry',
    method: 'get',
    params: { companyId: companyId }
  })
  let res = {
    code: -1,
    data: null
  }
  let data = { params: { companyId: companyId } }
  let response = await request.get(`/api/lab/admin/v1/operation/entry`, data).then((data) => {
    res.code = 0
    res.data = data.data
    let operationStore=useOperationStore()
    operationStore.updateCheck(0)
    operationStore.updateData(data.data)
  }).catch((err) => {
    if (err.message == "A000203") {
      useUserStore().logout()
      ElMessage({
        message: '登录信息过期,准备前往登录界面',
        grouping:true,
        type: 'error'
      })
      res.code = 1
    }
    else {
      ElMessage({
        message: err.message,
        grouping:true,
        type: 'error'
      })
      res.code = 2
    }
  })
  return res
}